#include "common.h"

int main()
{
    //1.创造key值
    key_t key = ftok(PATHNAME,PROJ_ID);
    if(key < 0)
    {
        perror("ftok");
        return 1;
    }
    //2.创建共享内存
    int shmid = shmget(key,SIZE,IPC_CREAT);
    if(shmid < 0)
    {
        perror("shmget");
        return 1;
    }
    //3.连接并死循环等待client连接
    char* mem = shmat(shmid,NULL,0);
    if(mem == (void*)-1)
    {
        perror("shmat");
        return 1;
    }
    int i = 0;
    while(1)
    {
        //向共享内存写入数据
        mem[i] = 'A' + i;
        i++;
        mem[i] = '\0';
        sleep(1);
    }
    //4.解除连接
    int ret = shmdt(mem);
    if(ret < 0)
    {
        perror("shmdt");
        return 1;
    }
    
    return 0;
}